package tyw.com.userms.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import tyw.com.userms.R;
import tyw.com.userms.utils.DbManager;
import tyw.com.userms.model.User;

public class AddActivity extends AppCompatActivity implements View.OnClickListener {


    EditText edPhone, edName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        findViewById(R.id.btn_add).setOnClickListener(this);
        edPhone = findViewById(R.id.et_phone);
        edName = findViewById(R.id.et_name);
    }

    DbManager dbManager;

    @Override
    public void onClick(View v) {

        //添加数据

        String name = edName.getText().toString();
        String phone = edPhone.getText().toString();
        if (TextUtils.isEmpty(name)) {

            Toast.makeText(this, "姓名不能为空", Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(phone)) {

            Toast.makeText(this, "手机号码不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        dbManager = new DbManager(this);
        dbManager.addUser(new User(name, phone));
        setResult(RESULT_OK);
        finish();

    }
}
